/**
 * @description 相对路径转换成绝对路径方法
 * @param {string} url 相对路径
 * @param {null|string} base 基准路径
 * @returns {string} 绝对路径
 * @see https://www.zhangxinxu.com/wordpress/2020/01/js-relative-absolute-path/
 * @author zhangxinxu(.com)
 * @example
 * relativeToAbsolute("../images/zhangxinxu.png", "https://www.zhangxinxu.com");
 * // https://www.zhangxinxu.com/images/zhangxinxu.png
 */
export function relativeToAbsolute(url, base) {
  if (!base) {
    base = location.protocol + location.host;
  }
  return new URL(url, base).href;
}

/**
 * @description 相对地址绝对地址转换方法
 * @author zhangxinxu(.com)
 */
export function relative2absolute(url, base) {
  var ele = document.createElement("a");
  ele.href = (base || "") + url;
  return eleLink.href;
}
